package com.jx.lcs.usersession.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tianyu.jty.common.persistence.HibernateDao;
import com.tianyu.jty.common.service.BaseService;
import com.jx.lcs.usersession.dao.UserSessionDao;
import com.jx.lcs.usersession.entity.UserSession;

/**
 * 商品类型service
 * @author ty
 * @date 2015年1月22日
 */
@Service
@Transactional(readOnly=true)
public class UserSessionService extends BaseService<UserSession, String> {
	
	@Autowired
	private UserSessionDao userSessionDao;

	@Override
	public HibernateDao<UserSession, String> getEntityDao() {
		return userSessionDao;
	}
	/*
	 * 获取所有登录用户信息
	 * 
	*/
	public List<UserSession> findAllUserSession() {
		List<UserSession> list = userSessionDao.findBy("status", "0");
		List<UserSession> result = new ArrayList<UserSession>();
		if(list != null && list.size() > 0) {
			Map<String, String> map = new HashMap<String, String>();
			for(UserSession user:list) {
				if(StringUtils.isBlank(user.getUid())) 
					continue;
				
				if(!map.containsKey(user.getUid())) {
					map.put(user.getUid(), user.getUid());
					result.add(user);
				}
			}
		}
		return result;
	}
	/*
 * 通过手机号获取登录用户信息
 *
*/
	public List<UserSession> findUserSessionByTel(String tel) {
		return userSessionDao.findUserSessionByTel(tel);
	}

}
